class CustomSchemeUtil {
  static String? schemeNextPage;

  static const String TAG = "CustomSchemeURIUtil";
  static const String PATH = "/localpath";
  static const String NAME = "name";

  //从scheme解析出nextPage
  static String? getNextPage(String? link) {
    if (link == null || link.isEmpty) {
      return null;
    }
    Uri? uri = Uri.tryParse(link);
    if (uri == null) {
      return null;
    }
    // Check path
    String? path = uri.path;
    if (path != PATH) {
      return null;
    }
    // Check nextPath. getQueryParameter is already decoded
    return uri.queryParameters[NAME];
  }

  //先记录
  static void recordNextPage(String? link) {
    var nextPage = getNextPage(link);
    print('XlinksDebug nextPage:$nextPage');
    if (nextPage?.isEmpty == true) {
      return;
    }
    CustomSchemeUtil.schemeNextPage = nextPage;
  }

  static void checkGoSchemeNextPage() {
    //唤起app并跳转到指定页面
    var nextPage = CustomSchemeUtil.schemeNextPage;
    CustomSchemeUtil.schemeNextPage = null;
    if (nextPage?.isNotEmpty == true) {
      print('XlinksDebug nextPage:$nextPage');
    }
  }
}
